<?php
// +----------------------------------------------------------------------
// | 零云 [ 简单 高效 卓越 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.lingyun.net All rights reserved.
// +----------------------------------------------------------------------
// | Author: jry <598821125@qq.com>
// +----------------------------------------------------------------------
namespace Admin\Model;

use Common\Model\ModelModel;
use Util\Tree;

/**
 * 导航模型
 * @author jry <598821125@qq.com>
 */
class KolModel extends ModelModel
{
    public $tag1 = array('1'=>'美食','2'=>'艺术','3'=>'手工','4'=>'形体','5'=>'心理','6'=>'摄影','7'=>'礼仪');
    public $tag2 = array('1'=>'小仙女','2'=>'强迫症','3'=>'天生吃货','4'=>'女神经','5'=>'暖男','6'=>'脑洞大开','7'=>'颜值爆表','8'=>'天马行空','9'=>'唯美','10'=>'时尚达人');
    public $tag3 = array('1'=>'母婴','2'=>'亲子','3'=>'时尚','4'=>'智能家居','5'=>'金融','6'=>'珠宝','7'=>'奢侈品','8'=>'房地产');
    /**
     * 数据库表名
     * @author jry <598821125@qq.com>
     */
    protected $tableName = 'admin_kol';

    /**
     * 自动验证规则
     * @author jry <598821125@qq.com>
     */
    protected $_validate = array(
        array('name', 'require', '名字不能为空', self::MUST_VALIDATE, 'regex', self::MODEL_BOTH)
        
    );

    /**
     * 自动完成规则
     * @author jry <598821125@qq.com>
     */
    protected $_auto = array(
        array('create_time', 'time', self::MODEL_INSERT, 'function'),
        array('update_time', 'time', self::MODEL_BOTH, 'function'),
        array('status', '1', self::MODEL_INSERT),
    );

    /**
     * 查找后置操作
     * @author jry <598821125@qq.com>
     */
    protected function _after_find(&$result, $options)
    {
        if ($result['introimg'] >= 0) {
            $result['introimg_url'] = get_cover($result['introimg'], 'default');
        }
        if ($result['kvimg'] >=0) {
            $result['kvimg_url'] = get_cover($result['kvimg'], 'default');
        }
        if (!is_array($result['showimg'])) {
            $temp = explode(',', $result['showimg']);
            foreach ($temp as $v) {
                $result['showimg_url'][] = get_cover($v, 'default');
            }
        }

        $tag1 = explode(",",$result['tag1']);
        foreach ($tag1 as $val) {
            $result['tag1txt'][]  = $this->tag1[$val];
        }

        $tag2 = explode(",",$result['tag2']);
        foreach ($tag2 as $val) {
            $result['tag2txt'][]  = $this->tag2[$val];
        }

        $tag3 = explode(",",$result['domain']);
        foreach ($tag3 as $val) {
            $result['domaintxt'][]  = $this->tag3[$val];
        }

        
    }

    /**
     * 查找后置操作
     * @author jry <598821125@qq.com>
     */
    protected function _after_select(&$result, $options)
    {
        foreach ($result as &$record) {
            $this->_after_find($record, $options);
        }
    }

    /**
     * 获取列表
     * @author jry <598821125@qq.com>
     */
    public function getList($cid, $limit = 10, $page = 1, $order = null, $map = null)
    {
        $con["status"] = array("eq", '1');
        $con["cid"]    = array("eq", $cid);
        if ($map) {
            $map = array_merge($con, $map);
        }
        if (!$order) {
            $order = 'sort desc, id desc';
        }
        $list = $this->page($page, $limit)
            ->order($order)
            ->where($map)
            ->select();

        return $list;
    }

    
}
